
<!DOCTYPE html>
<html>

<!-- Head -->
<head>

	<title>旅居之家</title>

	<!-- Meta-Tags -->
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

		<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
	<!-- //Meta-Tags -->

	<!-- Style --> <link rel="stylesheet" href="css/style.css" type="text/css" media="all">


</head>
<!-- //Head -->

<!-- Body -->
<body>

	<h1>旅居之家</h1>

	<div class="container w3layouts agileits">

		<div class="login w3layouts agileits">
			<h2>登 录</h2>
			<form action="#" method="post" onsubmit="return false" id="login">
				<input type="text" id="username" name="username" placeholder="用户名" required="true">
				<input type="password" id="password" name="password" placeholder="密码" required="true">
			<div class="send-button w3layouts agileits">
					<input type="submit" onclick="login()" value="登 录"><label style="margin-left:20px;color: white;" id="loginError"></label>
			</div>
			</form>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>

	</div>

	<div class="footer w3layouts agileits">
		<p>Copyright &copy; lory 2018</p>
	</div>

</body>
<script type="text/javascript" src="js/jquery.min.js" ></script>
<!-- //Body -->
<script type="text/javascript">
    function login(){
    	if ($("#username").val() == "" || $("#password").val() == "") {
            $("#loginError").html("账户名或密码不能够为空！");
            return false;
        }else{
        	 $.ajax({
            //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "http://112.124.107.209:8082/login" ,//url
                data: $('#login').serialize(),
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.code == 200) {
                        window.location.href = "http://112.124.107.209:8082/index";
                    }else{
                        $("#loginError").text("账户名或密码错误！");
					}
                },
                error : function() {
                    alert("异常！");
                }
            });
        }
    }
	
</script>
</html>